﻿using MediatR;
using T.Settlement.API.Application.Command.InvoiceCommand;
using T.Settlement.Repository.SettlementInterface;

namespace T.Settlement.API.Application.CommandHandlers.InvoiceHandler
{
    public class InvoiceBatchDelCommandHandler : IRequestHandler<InvoiceBatchDelCommand, int>
    {
        private readonly IInvoiceSRepository _invoiceSRepository;
        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="invoiceSRepository"></param>
        public InvoiceBatchDelCommandHandler(IInvoiceSRepository invoiceSRepository)
        {
            _invoiceSRepository = invoiceSRepository;
        }

        public async Task<int> Handle(InvoiceBatchDelCommand request, CancellationToken cancellationToken)
        {
            var list = await _invoiceSRepository.GetAllAsync();
            var ilist=list.Where(x=>request.InvoiceId.Contains(x.InvoiceId.ToString())).ToList();
            foreach(var x in ilist)
            {
                x.IsDeleted = true;
            }
            return await _invoiceSRepository.UpdateRange(ilist);
        }
    }
}
